import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.List;

/**
 * Created with IntelliJ IDEA
 * Description
 * User：chenshu
 * Date：2024-07-01
 * Time：13:40
 */
public class RedisDemoList {
    public static void main(String[] args) {
        JedisPool jedisPool = new JedisPool("tcp://127.0.0.1:8888");
        try(Jedis jedis = jedisPool.getResource()) {
            test6(jedis);
        }
    }

    private static void test6(Jedis jedis) {
        System.out.println("llen");
        jedis.flushDB();

        jedis.rpush("key", "1", "2", "3");
        System.out.println(jedis.llen("key"));
    }

    private static void test5(Jedis jedis) {
        System.out.println("blpop");
        jedis.flushDB();

        //存储key + value
        List<String> results = jedis.blpop(100, "key");
        System.out.println(results.get(0));
        System.out.println(results.get(1));
    }

    private static void test4(Jedis jedis) {
        System.out.println("rpop");
        jedis.flushDB();

        jedis.rpush("key", "1", "2", "3");

        String result = jedis.rpop("key");
        System.out.println(result);

        result = jedis.rpop("key");
        System.out.println(result);

        result = jedis.rpop("key");
        System.out.println(result);

        result = jedis.rpop("key");
        System.out.println(result);
    }

    private static void test3(Jedis jedis) {
        System.out.println("lpop");
        jedis.flushDB();

        jedis.rpush("key", "1", "2", "3");

        String result = jedis.lpop("key");
        System.out.println(result);

        result = jedis.lpop("key");
        System.out.println(result);

        result = jedis.lpop("key");
        System.out.println(result);

        result = jedis.lpop("key");
        System.out.println(result);
    }


    private static void test2(Jedis jedis) {
        System.out.println("rpush");
        jedis.flushDB();

        jedis.rpush("key", "1", "2", "3");
        List<String> ret = jedis.lrange("key", 0, -1);
        System.out.println(ret);
    }

    private static void test1(Jedis jedis) {
        System.out.println("lpush");
        jedis.flushDB();

        jedis.lpush("key", "1", "2", "3");
        List<String> ret = jedis.lrange("key", 0, -1);
        System.out.println(ret);
    }
}
